package modelTest.view.scoreDrawers;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

import modelTest.view.ScoreDrawer;
import modelTest.view.ViewParam;

public class TopCentreScoreDrawer implements ScoreDrawer{

	private int width;
	private Font scoreFont;
	private Color scoreColor;
	private int x;
	private int y;
	private int scoreSize = 0;
	
	public TopCentreScoreDrawer(Font scoreFont, Color scoreColor) {
		this.width = ViewParam.WIDTH;
		this.scoreFont = scoreFont;
		this.scoreColor = scoreColor;
	}
	
	public void setScoreColor(Color scoreColor) {
		this.scoreColor = scoreColor;
	}
	
	@Override
	public void drawScore(Graphics g, long score) {
		
		String scoreString = score +"";
		int length = scoreString.length();
		
		if( scoreSize < length ){
			scoreSize = length;
			
			Graphics2D g2d = (Graphics2D) g;
	        FontMetrics fm = g2d.getFontMetrics(scoreFont);
	        Rectangle2D r = fm.getStringBounds(scoreString, g2d);
	        x = (width - (int) r.getWidth()) / 2;
	        y = fm.getAscent();
		}
        
        g.setFont(scoreFont);
        g.setColor(scoreColor);
        g.drawString(scoreString, x, y);
	}
	
}
